import QtQuick
import QtQuick3D

import QtQuickRO

//实体生成器，可以作为敌人或玩家的出生点
//一个生成器可以搭配多个出生点，随机在某个出生点生成实体,没有出生点则以实体生成器自身的位置生成实体
//实体的parent和生成器的parent相同
Node{
    id:root
    //实体类型
    property Component sourceComponent

    ROComponent{
        id:rocomp

        comp: sourceComponent
    }

    property list<SpawnPoint> spawnPoints:{
        let ret = []
        for(var i in children)
        {
            let p = children[i]
            if(p instanceof SpawnPoint)
            {
                ret.push(p)
            }
        }

        return ret
    }

    function spawn(prop = {}){
        var spawnPoint = null

        if(spawnPoints.length === 0)
        {
            spawnPoint = this
        }
        else{
            spawnPoint = spawnPoints[Math.floor(Math.random() * spawnPoints.length)]
        }
        let pos = spawnPoint.mapPositionToNode(root.parent,Qt.vector3d(0,0,0))

        prop["position"] = pos
        prop["parent"] = root.parent
        return rocomp.spawnObject(prop)
    }

}
